home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / UDDIWEB.MSI / global.asax < prev    next >
Encoding:
Text File  |  2003-02-21  |  7.9 KB  |  278 lines

  1. <%@ Import Namespace='System.Data.SqlClient' %>
  2. <%@ Import Namespace='System.Security.Principal' %>
  3. <%@ Import Namespace='UDDI' %>
  4. <%@ Import Namespace='UDDI.Diagnostics' %>
  5. <%@ Import Namespace='UDDI.Web' %>
  6. <script language='C#' runat='server'>             
  7.     private const string publisherPages = 
  8.         "{/register.aspx}" +
  9.         "{/validate.aspx}" +
  10.         "{/admin/admin.aspx}" +
  11.         "{/admin/categorization.aspx}" +
  12.         "{/admin/changeowner.aspx}" +
  13.         "{/admin/default.aspx}" +
  14.         "{/admin/impersonate.aspx}" +
  15.         "{/admin/statistics.aspx}" +
  16.         "{/admin/taxonomy.aspx}" +        
  17.         "{/edit/default.aspx}" +        
  18.         "{/edit/edit.aspx}" +    
  19.         "{/edit/editbinding.aspx}" +
  20.         "{/edit/editbusiness.aspx}" +
  21.         "{/edit/editcontact.aspx}" +
  22.         "{/edit/editinstanceinfo.aspx}" +
  23.         "{/edit/editmodel.aspx}" +
  24.         "{/edit/editservice.aspx}" +
  25.         "{/edit/explorer.aspx}" +
  26.         "{/edit/frames.aspx}" +
  27.         "{/edit/help.aspx}";
  28.  
  29.     /// ***********************************************************************
  30.     ///   public Application_BeginRequest
  31.     /// -----------------------------------------------------------------------
  32.     ///   <summary>
  33.     ///     Called when page processing is begun.
  34.     ///   </summary>
  35.     /// ***********************************************************************
  36.     ///
  37.     public void Application_BeginRequest( object source, EventArgs eventArgs )
  38.     {    
  39.         //
  40.         // Get the virtual path to the script being executed. 
  41.         //
  42.  
  43.         string thisPage = Request.ServerVariables[ "SCRIPT_NAME" ];
  44.  
  45.         //
  46.         // Don't do any further processing for SOAP Web Service files (asmx) and default discoveryURL HTTP handler files (ashx)
  47.         // These interfaces handle their own database connections and SSL checks.
  48.         //
  49.         
  50.         if( thisPage.IndexOf( ".asmx" ) >= 0 || thisPage.IndexOf( ".ashx" ) >= 0 )
  51.             return;
  52.  
  53.         //
  54.         // Initialize our context ONCE per request.  This call is executeted for both our web site
  55.         // as well as the SOAP API.
  56.         //        
  57.         UDDI.Context.Current.Initialize();
  58.  
  59.  
  60.         //
  61.         // Do not remove this call, we need this log information to diagnose issues with
  62.         // Context initialization.
  63.         //    
  64.         Debug.Write(
  65.             SeverityType.Info,
  66.             CategoryType.Website,
  67.             "Application_BeginRequest");
  68.         
  69.         //
  70.         //  Reset the Users Roles to make sure they weren't 
  71.         //    revoked privlages between requests.
  72.         //
  73.         
  74.         //
  75.         // Don't do this, the Role will be set in the security control, or remain anonymous.
  76.         //
  77. //        UDDI.Context.User.SetRole( new WindowsPrincipal( WindowsIdentity.GetCurrent() ) );
  78.         
  79.         //
  80.         // Get the virual application root path.
  81.         // Handle special case when vdir is the root. In this case set it to a blank string to avoid an extra trailing "/".
  82.         //
  83.         
  84.         string root = ( "/" == Request.ApplicationPath ) ? "" : Request.ApplicationPath;
  85.  
  86.         //
  87.         // At this point we are only dealing with ASP.NET web pages (aspx)
  88.         //
  89.         
  90.         Debug.Enter();
  91.     
  92.         thisPage = thisPage.Substring( root.Length );
  93.     
  94.         Debug.Write(
  95.             SeverityType.Info,
  96.             CategoryType.Website,
  97.             "thisPage=" + thisPage );
  98.  
  99.         //
  100.         // Determine whether transactions are required.  Transactions are required for all publisher pages.
  101.         //        
  102.         bool publisherPage = false;
  103.  
  104.         if( -1 != publisherPages.IndexOf( "{" + thisPage.ToLower() + "}" ) )
  105.             publisherPage = true;
  106.  
  107.  
  108.         //
  109.         // If the System Web Server is set to Stop Mode, then write message and
  110.         // Stop processing the Request.
  111.         //
  112.         if( 0==Config.GetInt( "Run", UDDI.Constants.Run ) )
  113.         {
  114.             Context.AddError( new UDDIException( ErrorType.E_fatalError,Localization.GetString( "ERROR_SITESTOP" )  ) );
  115.             
  116.             Response.End();
  117.         }
  118.         
  119.     
  120.  
  121.         //
  122.         // Check to see if SSL is required.
  123.         //
  124.         
  125.         if( publisherPage && 1 == Config.GetInt( "Security.HTTPS", UDDI.Constants.Security.HTTPS ) && !Request.IsSecureConnection )
  126.         {
  127.             Context.AddError( new UDDIException( ErrorType.E_fatalError,Localization.GetString( "ERROR_HTTPSREQUIRED" )  ) );
  128.             //Response.Write( "<h1>Access denied</h1>This page requires a HTTPS secure connection." );
  129.             Response.End();
  130.         }    
  131.         
  132.         //
  133.         // Open the write database (UI always goes through the write database).
  134.         //
  135.         ConnectionManager.Open( true, publisherPage );
  136.  
  137.         Debug.Leave();
  138.     }
  139.     
  140.     /// ***********************************************************************
  141.     ///   public Application_EndRequest
  142.     /// -----------------------------------------------------------------------
  143.     ///   <summary>
  144.     ///     Called when page processing is completed.
  145.     ///   </summary>
  146.     /// ***********************************************************************
  147.     ///
  148.     public void Application_EndRequest( object source, EventArgs eventArgs )
  149.     {
  150.         //
  151.         // Do not remove this call, we need this log information to diagnose issues with
  152.         // Context initialization.
  153.         //    
  154.         Debug.Write(
  155.             SeverityType.Info,
  156.             CategoryType.Website,
  157.             "Application_EndRequest");
  158.             
  159.         //
  160.         // Get the virtual path to the script being executed. 
  161.         //
  162.  
  163.         string thisPage = Request.ServerVariables["SCRIPT_NAME"];
  164.  
  165.         //
  166.         // Don't do any further processing for SOAP Web Service files (asmx) and default discoveryURL HTTP handler files (ashx)
  167.         // These interfaces handle their own database connections.
  168.         //
  169.  
  170.         if( thisPage.IndexOf( ".asmx" ) >= 0 || thisPage.IndexOf( ".ashx" ) >= 0 )
  171.             return;
  172.  
  173.         Debug.Enter();
  174.  
  175.         //
  176.         // If there is an open database connection, close it.  We'll also
  177.         // check if there is an open transaction, and if there is, commit
  178.         // it.
  179.         //
  180.  
  181.         if( Context.Items.Contains( "Connection" ) )
  182.         {
  183.             if( null != ConnectionManager.GetTransaction() )
  184.             {
  185.                 Debug.Write( 
  186.                     SeverityType.Info,
  187.                     CategoryType.Website,
  188.                     "Committing database transaction" );
  189.  
  190.                 ConnectionManager.Commit();
  191.             }
  192.  
  193.             Debug.Write( 
  194.                 SeverityType.Info,
  195.                 CategoryType.Website,
  196.                 "Closing database connection" );
  197.  
  198.             ConnectionManager.Close();
  199.         }
  200.  
  201.         Debug.Leave();
  202.     }
  203.  
  204.     /// ***********************************************************************
  205.     ///   public Application_Error
  206.     /// -----------------------------------------------------------------------
  207.     ///   <summary>
  208.     ///     Called when an unhandled exception is encountered while processing
  209.     ///     the page.
  210.     ///   </summary>
  211.     /// ***********************************************************************
  212.     ///
  213.     public void Application_Error( object source, EventArgs eventArgs )
  214.     {
  215.         //
  216.         // Get the virtual path to the script being executed. 
  217.         //
  218.  
  219.         string thisPage = Request.ServerVariables["SCRIPT_NAME"];
  220.  
  221.         //
  222.         // Don't do any further processing for SOAP Web Service files (asmx) and default discoveryURL HTTP handler files (ashx)
  223.         // These interfaces handle their own errors and database connections.
  224.         //
  225.         
  226.         if( thisPage.IndexOf( ".asmx" ) >= 0 || thisPage.IndexOf( ".ashx" ) >= 0 )
  227.             return;
  228.  
  229.         Debug.Enter();
  230.  
  231.         //
  232.         // Get the virual application root path.
  233.         // Handle special case when vdir is the root. In this case set it to a blank string to avoid an extra trailing "/".
  234.         //
  235.  
  236.         string root = ( "/" == Request.ApplicationPath ) ? "" : Request.ApplicationPath;
  237.         
  238.         //
  239.         // If a database connection is open and there is a transaction
  240.         // abort it.
  241.         //        
  242.         if( Context.Items.Contains( "Connection" ) )            
  243.         {
  244.             if( null != ConnectionManager.GetTransaction() )
  245.             {
  246.                 Debug.Write( 
  247.                     SeverityType.Info,
  248.                     CategoryType.Website,
  249.                     "Aborting database transaction" );
  250.  
  251.                 ConnectionManager.Abort();
  252.             }
  253.             
  254.             ConnectionManager.Close();
  255.         }
  256.  
  257.         //
  258.         // Transfer to an error page.
  259.         //
  260.         Debug.Write( 
  261.             SeverityType.Info,
  262.             CategoryType.Website,
  263.             "Exception was thrown: " + Context.Error.ToString() );
  264.         
  265.         bool frames = ( "true" == Request[ "frames" ] );
  266.         
  267.         Session[ "exception" ] = Context.Error;        
  268.         Context.ClearError();
  269.         
  270.         Response.Clear();  
  271.         
  272.         HttpContext.Current.Response.ClearContent();
  273.                 
  274.         Debug.Leave();
  275.         
  276.         Server.Transfer( root + "/error.aspx?frames=" + ( frames ? "true" : "false" ) );
  277.     }
  278. </script>